package com.gsy.springai1.repository;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Component
@RequiredArgsConstructor
public class InmemoryChatHistoryRepository implements ChatHistoryRepository {

    //使用map集合进行存储
   private Map<String ,List<String>> chatHistory = new HashMap<>();

    @Override
    public void save(String type, String chaId) {
        if (!chatHistory.containsKey(type)) {
            chatHistory.put(type, new ArrayList<>());
        }
        List<String> chatIds = chatHistory.get(type);
        if (!chatIds.contains(chaId)) {
            chatIds.add(chaId);
        }else {
             return ;
        }
    }

    @Override
    public List<String> getChatIds(String type) {
        List<String> chatIds = chatHistory.get(type);

        return chatIds == null ? List.of() : chatIds;
    }
}
